package com.common.help;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

public class Test14 {
	public static void main(String[] args) {
		MyListMapTest test = new MyListMapTest();
		test.put("aa", "1");
		test.put("bb", "2");
		test.put("cc", "3");
		test.put("dd", "4");
		
		for(int i=0;i<test.getSize();i++){
			System.out.println(test.getKey(i)+"-->"+test.getValue(i));
		}
	
		Map<String,Object> hash = test.getHashMap();
		
		for(String key:hash.keySet()){
			System.out.println(key+"-->"+hash.get(key));
		}
		
		Iterator<Map.Entry<String, Object>> it = hash.entrySet().iterator();
		while(it.hasNext()){
			Entry<String,Object> entry = it.next();
			System.out.println(entry.getKey()+"-->"+entry.getValue());
		}
		
		
		
	}

	
	
}
class MyListMapTest{
	
	private Map<String,Object> hashMap;
	
	private List list;
	
	
	
	// list -> a,b,c
	// hashMap-> a=11，b=22 ,c=33;
	
	public Map getHashMap() {
		return hashMap;
	}

	public void setHashMap(Map hashMap) {
		this.hashMap = hashMap;
	}

	public List getList() {
		return list;
	}

	public void setList(List list) {
		this.list = list;
	}

	public MyListMapTest(){
		this.hashMap = new HashMap<String,Object>();
		this.list = new ArrayList();
	}
	
	public void put(Object key,Object value){
		if(list.contains(key)){
			list.remove(key);
		}
		this.list.add(key);
		
		hashMap.put(key.toString(), value);
	}
	
	//取得是 靠list的有序 来取
	public Object getKey(int i){
		return this.list.get(i);  
	}
	public Object getValue(Object key){
		return hashMap.get(key);
	}
	
	public Object getValue(int i){
		return hashMap.get(this.getKey(i));
	}
	
	public int getSize(){
		return list.size();
	}
}